﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>填充从表</title>
    <link href="../../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script src="../../../Scripts/easyUI145/jquery.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/easyUI145/jquery.easyui.min.js" type="text/javascript"></script>

    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../../Comm/Gener.js" type="text/javascript"></script>
    <script src="DDLBar.js" type="text/javascript"></script>
    <script src="../../CCFlowEnum.js" type="text/javascript"></script>
    <script src="../../Admin.js"></script>
    <script type="text/javascript">

        $(function () {

            InitBar("Dtls");

            //查询出来数据.
            //更新节点表单类型.
            var frmID = GetQueryString("FK_MapData");
            var refPK = GetQueryString("RefPK");

            var thisPK = refPK + "_FullData";

            var en = new Entity("BP.Sys.MapExt");
            en.MyPK = refPK + "_FullData";
            en.SetPKVal(en.MyPK);
            var n = en.RetrieveFromDBSources();

            var tag1 = en.Tag1;

            //            alert(tag1);

            //获得从表.
            var mapDtls = new Entities("BP.Sys.MapDtls");
            mapDtls.Retrieve("FK_MapData", frmID);

            if (mapDtls.length == 0) {
                $("#doc").html("<h3>该表单没有从表.</h3>");
                return;
            }

            var html = "<table style='width:99%;'>";
            for (var i = 0; i < mapDtls.length; i++) {
                var sql = "";
                if (tag1 != "" && tag1 != null) {
                    sql = tag1.split("$")[i + 1].split(":")[1]; //分割字符串，获取sql语句
                }

                var dtl = mapDtls[i];
                html += "<tr>";
                html += "<th>" + dtl.No + " - " + dtl.Name+"</th>";
                html += "</tr>";

                html += "<tr>";
                html += "<td>";
                html += "<textarea id='" + dtl.No + "' style='width:98%;' >" + FormatSQL( sql) + "</textarea>";
                html += "</td>";
                html += "</tr>";

            }

            $("#doc").html(html);

        });

        function Save() {

            //更新节点表单类型.
            var frmID = GetQueryString("FK_MapData");
            var refPK = GetQueryString("RefPK");

            var thisPK = refPK + "_FullData";

            var en = new Entity("BP.Sys.MapExt");
            en.MyPK = refPK + "_FullData";
            en.SetPKVal(en.MyPK);
            var n = en.RetrieveFromDBSources();
            en.FK_MapData = frmID;
            en.ExtType = "FullData";

            //生成SQL, 执行保存.
            //格式为: #ND101$ SELECT * FROM SXX WHERE AA='11';

            //获得从表.
            var mapDtls = new Entities("BP.Sys.MapDtls");
            mapDtls.Retrieve("FK_MapData", frmID);


            var tag1 = "";
            for (var i = 0; i < mapDtls.length; i++) {

                var dtl = mapDtls[i];

                var sql = $("#" + dtl.No).val();
                tag1 += "$" + dtl.No + ":" + sql;
            }
            en.Tag1 = tag1;
            en.AttrOfOper = GetQueryString("KeyOfEn");

            if (n == 0)
                en.Insert();
            else
                en.Update();

            window.location.href = window.location.href;
        }
    </script>
</head>
<body>
    <form id="cc">

        <div id="bar"> </div>
        <div id="doc"></div>

        <fieldset >
            <legend id="help">帮助.</legend>
            <ul>
                <li>填充从表的SQL </li>
                <li>返回一个数据源，该数据源的列，需要与从表的列匹配，对于匹配上的数据自动填充.</li>
                <li>实例:<font color="green">SELECT * FROM Demo_Resume WHERE RefPK='@Key' </font></li>
                <li>@Key 是系统约定的标记，就是选择的编号或者ID. </li>
                <li>这个数据源就会清空的方式复制到从表里面去. </li>
            </ul>
        </fieldset>
    </form>
</body>
</html>
